<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <!-- 搜索区域 -->
      <a-form-model
        ref="formModel"
        :model="form"
        layout="inline"
        :rules="{
          name: [
            {
              validator: validators.noWhitespace(),
              trigger: 'change',
            },
            {
              validator: validators.noIllegalString(),
              trigger: 'change',
            },
            {
              max: 10,
              message: '长度在 1 到 10 个字符',
              trigger: 'change',
            },
          ],
        }"
      >
        <a-row :gutter="[16, 16]" type="flex" justify="end">
          <a-col :md="6" :sm="8">
            <a-form-model-item prop="name" label="应用名称">
              <a-input autocomplete="off" v-model="form.name" />
            </a-form-model-item>
          </a-col>
          <span
            style="float: left; overflow: hidden"
            class="table-page-search-submitButtons"
          >
            <a-col :md="12" :sm="24">
              <a-button
                type="primary"
                @click="loadData(true)"
                icon="search"
                style="margin-left: 21px"
                >查询</a-button
              >
              <a-button
                @click="resetSearchForm"
                icon="reload"
                style="margin-left: 8px"
                >重置</a-button
              >
            </a-col>
          </span>
        </a-row>
      </a-form-model>
    </div>

    <a-table
      ref="table"
      rowKey="id"
      size="middle"
      :columns="columns"
      :dataSource="gDataSource"
      :pagination="gPagination"
      @change="gHandleTableChange"
    >
      <span slot="sortCol" slot-scope="text, record, index">
        {{
          (gPagination.current - 1) * gPagination.pageSize + parseInt(index) + 1
        }}
      </span>
      <span slot="statusCol" slot-scope="text, record">
        <template v-if="record.status === 1">
          <!-- <a-icon type="loading" style="font-size: 14px" /> -->
          <a-spin />
        </template>
        <template v-else-if="record.status === 2">
          <a-icon type="close-circle" style="font-size: 14px; color: red" />
        </template>
        <template v-else>
          <a-icon type="check-circle" style="font-size: 14px; color: green" />
        </template>
      </span>
      <span
        slot="instance"
         slot-scope="text"
      >
        <!-- <template v-if="record.cloudResourceTypeName === '容器云'">
          <a-icon type="cloud" />
        </template>
        <template v-else>
          <a-icon type="desktop" />
        </template> -->
        <a-icon type="desktop" />
        {{ text }}
      </span>
      <span slot="action" slot-scope="text, record">
        <a-button v-if="record.statusName === '正常'" type="primary" size="small" icon="edit" @click="handleTranfer(record)">
          迁移
        </a-button>
      </span>
    </a-table>
    <tranfer-modal ref="tranferModal"></tranfer-modal>
  </a-card>
</template>

<script>
import TranferModal from "./modules/TranferModal";
import { GwListMixin } from "@/mixins/GwListMixin";
import { gPostAction } from "@/api/manage";

export default {
  name: "F0204",
  mixins: [GwListMixin],
  components: {
    TranferModal,
  },
  data() {
    return {
      // 表头
      columns: [
        {
          title: "序号",
          dataIndex: "",
          key: "rowIndex",
          width: 50,
          scopedSlots: { customRender: "sortCol" },
        },
        {
          title: "应用名称",
          dataIndex: "appName",
        },
        {
          title: "状态",
          dataIndex: "statusName",
          scopedSlots: { customRender: "statusCol" },
        },
        {
          title: "调度实例",
          dataIndex: "instanceName",
          scopedSlots: { customRender: "instance" },
        },
        {
          title: "原数据中心",
          dataIndex: "datacenterName",
        },
        {
          title: "云平台资源",
          dataIndex: "resourceName",
        },
        {
          title: "操作",
          width: "150px",
          dataIndex: "",
          scopedSlots: { customRender: "action" },
        },
      ],
      schedulerModelTypeMap: ["最优成本代价模型", "最优设备代价模型"],
      schedulerModelToolTypeMap: [
        "Kubernetes迁移工具",
        "阿里云迁移工具",
        "华为迁移工具",
      ],
      schedulerStrategyConfigTypeMap: ["全量迁移", "模版迁移"],
      form: {
        name: "",
      },
    };
  },
  mounted() {
    this.loadData();
  },
  methods: {
    handleTranfer(data) {
      this.$refs.tranferModal.tranfer(data);
    },
    loadData(isDoSearch) {
      this.$refs.formModel.validate((error) => {
        if (!error) {
          return;
        }
        this.gQueryParam.name = this.form.name;
        // this.gQueryParam.title = "多数据中心调度-动态调度机制-调度建议";
        // this.gQueryParam.content = "查询调度建议列表";
        this.gQueryParam.status = this.form.status;
        if (isDoSearch) {
          this.gQueryParam.pageNo = 1;
          this.gPagination.current = 1;
        }
        gPostAction("/app/instancePage", this.gQueryParam).then((res) => {
          if (res.success) {
            this.gDataSource = res.data.list;
            this.gPagination.total = res.data.totalCount;
          }
        });
      });
    },
    resetSearchForm() {
      this.form.name = "";
      this.$refs.formModel.resetFields();
    },
  },
};
</script>